/*
 * ResXMLTreeNode.h
 *
 *  Created on: May 26, 2018
 *      Author: hp
 */

#ifndef RESXMLTREENODE_H_
#define RESXMLTREENODE_H_

#include <stdint.h>

#include "android-xml.h"

#include "ResStringPool.h"
#include "ResValue.h"

class XMLNameSpace;

struct ResXMLTreeNodeAttribute {
	const char* ns;
	const char* name;
	const char* rawValue;
	ResValue typedValue;
};

class ResXMLTreeNode {
public:
	ResXMLTreeNode(bool root = false);
	ResXMLTreeNode(const ResStringPool& string_pool, const char* data);

	void add_attribute(ResXMLTreeNodeAttribute* attribute);
	void add_child(ResXMLTreeNode* child);

	uint32_t serialize(ResStringPool& string_pool, char** data);

	void dump(const XMLNameSpace* ns, bool ns_declared = true);
	virtual ~ResXMLTreeNode();

	ResXMLTreeNode* _parent = nullptr;

	const char* _name = nullptr;
	const char* _ns = nullptr;
	ResXMLTreeNodeAttribute** _attributes = nullptr;
	uint32_t _num_attributes = 0;
	ResXMLTreeNode** _children = nullptr;
	uint32_t _num_children = 0;
	bool _root = false;
};

#endif /* RESXMLTREENODE_H_ */
